home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / Power_Fact2056133262007.psc / pf corrector designer / Form1.frm next >
Text File  |  2007-03-26  |  15KB  |  572 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Power Factor Corrector"
  4.    ClientHeight    =   8490
  5.    ClientLeft      =   60
  6.    ClientTop       =   450
  7.    ClientWidth     =   9405
  8.    LinkTopic       =   "Form1"
  9.    MaxButton       =   0   'False
  10.    ScaleHeight     =   8490
  11.    ScaleWidth      =   9405
  12.    StartUpPosition =   2  'CenterScreen
  13.    Begin VB.VScrollBar VScroll3 
  14.       Height          =   3975
  15.       Left            =   9120
  16.       Max             =   50
  17.       Min             =   1
  18.       TabIndex        =   26
  19.       Top             =   4320
  20.       Value           =   1
  21.       Width           =   255
  22.    End
  23.    Begin VB.Timer Timer2 
  24.       Interval        =   17
  25.       Left            =   6600
  26.       Top             =   360
  27.    End
  28.    Begin VB.PictureBox pic 
  29.       AutoRedraw      =   -1  'True
  30.       BackColor       =   &H80000012&
  31.       Height          =   3975
  32.       Left            =   240
  33.       ScaleHeight     =   3915
  34.       ScaleWidth      =   8835
  35.       TabIndex        =   20
  36.       Top             =   4320
  37.       Width           =   8895
  38.    End
  39.    Begin VB.CommandButton Command2 
  40.       Caption         =   "STOP"
  41.       BeginProperty Font 
  42.          Name            =   "MS Sans Serif"
  43.          Size            =   8.25
  44.          Charset         =   0
  45.          Weight          =   700
  46.          Underline       =   0   'False
  47.          Italic          =   0   'False
  48.          Strikethrough   =   0   'False
  49.       EndProperty
  50.       Height          =   375
  51.       Left            =   1320
  52.       TabIndex        =   16
  53.       Top             =   0
  54.       Width           =   1215
  55.    End
  56.    Begin VB.Timer Timer1 
  57.       Interval        =   17
  58.       Left            =   7800
  59.       Top             =   240
  60.    End
  61.    Begin VB.VScrollBar VScroll2 
  62.       Height          =   1335
  63.       Left            =   7440
  64.       Max             =   100
  65.       Min             =   1
  66.       TabIndex        =   13
  67.       Top             =   2400
  68.       Value           =   1
  69.       Width           =   255
  70.    End
  71.    Begin VB.VScrollBar VScroll1 
  72.       Height          =   1335
  73.       Left            =   6720
  74.       Max             =   3000
  75.       Min             =   1
  76.       TabIndex        =   12
  77.       Top             =   2400
  78.       Value           =   1
  79.       Width           =   255
  80.    End
  81.    Begin VB.TextBox txtpf 
  82.       Height          =   285
  83.       Left            =   6720
  84.       TabIndex        =   9
  85.       Top             =   1920
  86.       Width           =   855
  87.    End
  88.    Begin VB.CheckBox Check1 
  89.       Caption         =   "Click to connect capacitor"
  90.       Height          =   435
  91.       Left            =   3840
  92.       TabIndex        =   8
  93.       Top             =   1080
  94.       Width           =   1935
  95.    End
  96.    Begin VB.CommandButton Command1 
  97.       Caption         =   "SIMULATE"
  98.       BeginProperty Font 
  99.          Name            =   "MS Sans Serif"
  100.          Size            =   8.25
  101.          Charset         =   0
  102.          Weight          =   700
  103.          Underline       =   0   'False
  104.          Italic          =   0   'False
  105.          Strikethrough   =   0   'False
  106.       EndProperty
  107.       Height          =   375
  108.       Left            =   0
  109.       TabIndex        =   4
  110.       Top             =   0
  111.       Width           =   1335
  112.    End
  113.    Begin VB.TextBox txtload 
  114.       Height          =   285
  115.       Left            =   6720
  116.       TabIndex        =   3
  117.       Top             =   1560
  118.       Width           =   855
  119.    End
  120.    Begin VB.TextBox txtcap 
  121.       Height          =   285
  122.       Left            =   4080
  123.       TabIndex        =   2
  124.       Top             =   2160
  125.       Width           =   495
  126.    End
  127.    Begin VB.TextBox txtammeter 
  128.       Height          =   285
  129.       Left            =   1560
  130.       TabIndex        =   1
  131.       Top             =   690
  132.       Width           =   855
  133.    End
  134.    Begin VB.TextBox txtsource 
  135.       Height          =   285
  136.       Left            =   1560
  137.       TabIndex        =   0
  138.       Top             =   1920
  139.       Width           =   855
  140.    End
  141.    Begin VB.Label Label15 
  142.       Height          =   255
  143.       Left            =   8280
  144.       TabIndex        =   27
  145.       Top             =   4080
  146.       Width           =   1095
  147.    End
  148.    Begin VB.Label Label14 
  149.       Caption         =   "PF corrector"
  150.       Height          =   255
  151.       Left            =   2880
  152.       TabIndex        =   25
  153.       Top             =   2160
  154.       Width           =   975
  155.    End
  156.    Begin VB.Label Label13 
  157.       Caption         =   "Legend:"
  158.       Height          =   255
  159.       Left            =   240
  160.       TabIndex        =   24
  161.       Top             =   3600
  162.       Width           =   735
  163.    End
  164.    Begin VB.Label Label12 
  165.       Caption         =   "Power Wave From"
  166.       Height          =   255
  167.       Left            =   3120
  168.       TabIndex        =   23
  169.       Top             =   3960
  170.       Width           =   1695
  171.    End
  172.    Begin VB.Line Line13 
  173.       BorderColor     =   &H0000FFFF&
  174.       BorderWidth     =   3
  175.       X1              =   1080
  176.       X2              =   2880
  177.       Y1              =   4080
  178.       Y2              =   4080
  179.    End
  180.    Begin VB.Label Label11 
  181.       Caption         =   "Current Wave Form"
  182.       Height          =   255
  183.       Left            =   3120
  184.       TabIndex        =   22
  185.       Top             =   3720
  186.       Width           =   1695
  187.    End
  188.    Begin VB.Line Line12 
  189.       BorderColor     =   &H00FFFFFF&
  190.       BorderWidth     =   3
  191.       X1              =   1080
  192.       X2              =   2880
  193.       Y1              =   3840
  194.       Y2              =   3840
  195.    End
  196.    Begin VB.Label Label10 
  197.       Caption         =   "Voltage Wave Form"
  198.       Height          =   255
  199.       Left            =   3120
  200.       TabIndex        =   21
  201.       Top             =   3480
  202.       Width           =   1695
  203.    End
  204.    Begin VB.Line Line11 
  205.       BorderColor     =   &H0000FF00&
  206.       BorderWidth     =   3
  207.       X1              =   1080
  208.       X2              =   2880
  209.       Y1              =   3600
  210.       Y2              =   3600
  211.    End
  212.    Begin VB.Label Label9 
  213.       Alignment       =   2  'Center
  214.       BackStyle       =   0  'Transparent
  215.       Caption         =   "S"
  216.       BeginProperty Font 
  217.          Name            =   "MS Sans Serif"
  218.          Size            =   24
  219.          Charset         =   0
  220.          Weight          =   400
  221.          Underline       =   0   'False
  222.          Italic          =   0   'False
  223.          Strikethrough   =   0   'False
  224.       EndProperty
  225.       ForeColor       =   &H000000FF&
  226.       Height          =   495
  227.       Left            =   720
  228.       TabIndex        =   19
  229.       Top             =   1680
  230.       Width           =   735
  231.    End
  232.    Begin VB.Shape Shape1 
  233.       BorderStyle     =   0  'Transparent
  234.       FillStyle       =   0  'Solid
  235.       Height          =   615
  236.       Left            =   720
  237.       Shape           =   2  'Oval
  238.       Top             =   1680
  239.       Width           =   735
  240.    End
  241.    Begin VB.Label Label3 
  242.       Caption         =   "microF"
  243.       Height          =   375
  244.       Left            =   4680
  245.       TabIndex        =   18
  246.       Top             =   2160
  247.       Width           =   615
  248.    End
  249.    Begin VB.Line Line10 
  250.       X1              =   3960
  251.       X2              =   3960
  252.       Y1              =   2040
  253.       Y2              =   3360
  254.    End
  255.    Begin VB.Line Line9 
  256.       BorderWidth     =   3
  257.       X1              =   3480
  258.       X2              =   4440
  259.       Y1              =   2040
  260.       Y2              =   2040
  261.    End
  262.    Begin VB.Line Line8 
  263.       BorderWidth     =   3
  264.       X1              =   3480
  265.       X2              =   4440
  266.       Y1              =   1920
  267.       Y2              =   1920
  268.    End
  269.    Begin VB.Line Line7 
  270.       X1              =   3960
  271.       X2              =   3960
  272.       Y1              =   840
  273.       Y2              =   1920
  274.    End
  275.    Begin VB.Label Label8 
  276.       Height          =   255
  277.       Left            =   7800
  278.       TabIndex        =   17
  279.       Top             =   2280
  280.       Width           =   1575
  281.    End
  282.    Begin VB.Label Label7 
  283.       Caption         =   "PF"
  284.       Height          =   255
  285.       Left            =   7440
  286.       TabIndex        =   15
  287.       Top             =   3840
  288.       Width           =   495
  289.    End
  290.    Begin VB.Label Label6 
  291.       Caption         =   "Load "
  292.       Height          =   255
  293.       Left            =   6600
  294.       TabIndex        =   14
  295.       Top             =   3840
  296.       Width           =   615
  297.    End
  298.    Begin VB.Label Label5 
  299.       Alignment       =   2  'Center
  300.       BackColor       =   &H000000C0&
  301.       Caption         =   "LOAD"
  302.       BeginProperty Font 
  303.          Name            =   "MS Sans Serif"
  304.          Size            =   8.25
  305.          Charset         =   0
  306.          Weight          =   700
  307.          Underline       =   0   'False
  308.          Italic          =   0   'False
  309.          Strikethrough   =   0   'False
  310.       EndProperty
  311.       ForeColor       =   &H00FFFF80&
  312.       Height          =   1215
  313.       Left            =   5760
  314.       TabIndex        =   11
  315.       Top             =   1440
  316.       Width           =   735
  317.    End
  318.    Begin VB.Label Label1 
  319.       Caption         =   "power factor"
  320.       Height          =   255
  321.       Left            =   7680
  322.       TabIndex        =   10
  323.       Top             =   1920
  324.       Width           =   1095
  325.    End
  326.    Begin VB.Label Label4 
  327.       Caption         =   "Load, watts"
  328.       Height          =   255
  329.       Left            =   7680
  330.       TabIndex        =   7
  331.       Top             =   1560
  332.       Width           =   1095
  333.    End
  334.    Begin VB.Label Label2 
  335.       Alignment       =   2  'Center
  336.       BackColor       =   &H00C0C0C0&
  337.       Caption         =   "Ammeter"
  338.       ForeColor       =   &H00FF0000&
  339.       Height          =   255
  340.       Left            =   1560
  341.       TabIndex        =   6
  342.       Top             =   480
  343.       Width           =   855
  344.    End
  345.    Begin VB.Label source 
  346.       Caption         =   "SOURCE"
  347.       Height          =   255
  348.       Left            =   1200
  349.       TabIndex        =   5
  350.       Top             =   2400
  351.       Width           =   1335
  352.    End
  353.    Begin VB.Line Line6 
  354.       X1              =   6120
  355.       X2              =   6120
  356.       Y1              =   3360
  357.       Y2              =   2640
  358.    End
  359.    Begin VB.Line Line5 
  360.       X1              =   6120
  361.       X2              =   6120
  362.       Y1              =   840
  363.       Y2              =   1440
  364.    End
  365.    Begin VB.Line Line4 
  366.       X1              =   1080
  367.       X2              =   6120
  368.       Y1              =   3360
  369.       Y2              =   3360
  370.    End
  371.    Begin VB.Line Line3 
  372.       X1              =   1080
  373.       X2              =   1080
  374.       Y1              =   2280
  375.       Y2              =   3360
  376.    End
  377.    Begin VB.Line Line2 
  378.       X1              =   1080
  379.       X2              =   6120
  380.       Y1              =   840
  381.       Y2              =   840
  382.    End
  383.    Begin VB.Line Line1 
  384.       X1              =   1080
  385.       X2              =   1080
  386.       Y1              =   2400
  387.       Y2              =   840
  388.    End
  389. End
  390. Attribute VB_Name = "Form1"
  391. Attribute VB_GlobalNameSpace = False
  392. Attribute VB_Creatable = False
  393. Attribute VB_PredeclaredId = True
  394. Attribute VB_Exposed = False
  395. 'Coded by Arnel Missiona
  396. 'www.geocities.com/arnelmissiona
  397.  
  398. Private OLDpf As Double
  399. Private corCAP As Double
  400. Private x As Double
  401. Private prevx1 As Double
  402. Private prevy1  As Double
  403. Private prevcy1 As Double
  404. Private prevpy1 As Double
  405. Private mult As Double
  406. Private center As Integer
  407. Private xmult As Integer
  408. Dim angle As Double
  409. Private angleLAG As Double
  410.  
  411.  
  412. Private Sub Check1_Click()
  413. On Error GoTo err
  414. Dim Capvar As Double
  415.  
  416. If Check1.Value = 1 Then
  417. OLDpf = txtpf
  418. xc = Round(1 / (2 * 3.1416 * 60 * txtcap) * 1000000, 2)
  419. Capvar = (txtsource ^ 2) / xc
  420.  
  421. va2 = (CDbl(txtload) / CDbl(txtpf)) ^ 2
  422. p2 = CDbl(txtload) ^ 2
  423. var = va2 - p2
  424. indvar = Sqr(var)
  425.  
  426. newvar = indvar - Capvar
  427.  
  428. newVA = Sqr(CDbl(txtload) ^ 2 + newvar ^ 2)
  429. newpf = txtload / newVA
  430. txtpf = Round(newpf, 4)
  431. Else
  432. txtpf = OLDpf
  433. End If
  434. err:
  435. End Sub
  436.  
  437. Private Sub Command1_Click()
  438. Timer1.Enabled = True
  439. Timer2.Enabled = True
  440. End Sub
  441.  
  442. Private Sub Command2_Click()
  443. Timer1.Enabled = False
  444. Timer2.Enabled = False
  445. End Sub
  446.  
  447. Private Sub Form_Load()
  448. Timer1.Enabled = False
  449. Timer2.Enabled = False
  450. source = "SOURCE: 220V"
  451. txtsource = 220
  452. txtload = 1
  453. txtpf = 1
  454. mult = 1 * 0.2
  455. center = pic.Height / 2
  456. xmult = 20
  457. End Sub
  458.  
  459. Private Function ampere(pf As Double, power As Double, volts As Double) As Double
  460. ampere = Round(power / (pf * volts), 2)
  461. End Function
  462.  
  463. Private Sub Timer1_Timer()
  464. Dim pf As Double
  465. Dim volts As Double
  466. Dim power As Double
  467. Dim var As Double
  468.  
  469.  
  470. pf = txtpf
  471. volts = txtsource
  472. power = txtload
  473.  
  474. txtammeter = ampere(pf, power, volts)
  475.  
  476. var = Sqr((txtload / txtpf) ^ 2 - txtload ^ 2)
  477. Label8 = "VAR: " & Round(var, 2)
  478. If Check1.Value = 0 Then
  479. txtcap = Round(capacitor(txtsource, var) * 1000000, 0)
  480. End If
  481. End Sub
  482.  
  483. Private Sub Timer2_Timer()
  484. On Error GoTo err
  485. Dim radANGLE As Double
  486. Dim radlagANGLE As Double
  487.  
  488. pic.DrawWidth = 1
  489. pic.Scale (0, pic.Height)-(pic.Width, 0)
  490.  
  491. xpf = txtpf
  492. If xpf <> 1 Then
  493. angleLAG = (Atn(-xpf / Sqr(-xpf * xpf + 1)) + 2 * Atn(1)) * (180 / 3.1416)
  494. Else
  495. angleLAG = 0
  496. End If
  497.  
  498.  
  499. x = (x + 1) + xmult 'scale
  500. angle = angle + 10 ' convert this to radians first
  501.  
  502. radANGLE = angle * (3.1416 / 180)  ' in radians
  503.  
  504. yval = Sin(radANGLE) * txtsource * mult + center
  505. cvalA = angle - angleLAG
  506.  
  507. radlagANGLE = cvalA * (3.1416 / 180) ' lagging angle in radians
  508.  
  509. lag = "Angle:" & angle & " anglelag:" & angleLAG & " LAG o:" & cvalA
  510.  
  511. cval = Sin(radlagANGLE) * CDbl(txtammeter) * (mult * 4) + center
  512. power = ((Sin(radANGLE) * txtsource * Sin(radlagANGLE) * CDbl(txtammeter)) * (mult / 2)) + center
  513.  
  514. If (x - xmult) = 1 Then
  515. pic.Line (0, yval)-(0, yval), vbGreen
  516. pic.Line (0, cval)-(0, cval), vbGreen
  517. pic.Line (0, power)-(0, power), vbGreen
  518. prevx1 = x
  519. prevy1 = yval
  520. prevcy1 = cval
  521. prevpy1 = power
  522. Else
  523.  
  524. pic.Line (0, center)-(pic.Width, center), vbRed
  525. pic.Line (prevx1, prevy1)-(x, yval), vbGreen
  526. pic.Line (prevx1, prevcy1)-(x, cval), vbWhite
  527. pic.Line (prevx1, prevpy1)-(x, power), vbYellow
  528.  
  529.  
  530. prevx1 = x
  531. prevy1 = yval
  532. prevcy1 = cval
  533. prevpy1 = power
  534. End If
  535.  
  536. If x > pic.Width Then x = 0: pic.Cls
  537.  
  538. err:
  539. 'MsgBox err.Description
  540. End Sub
  541.  
  542. Private Sub VScroll1_Scroll()
  543. txtload = VScroll1.Value
  544. End Sub
  545.  
  546. Private Sub VScroll2_Change()
  547. txtpf = VScroll2.Value / 100
  548. End Sub
  549.  
  550. Private Sub VScroll2_Scroll()
  551. txtpf = VScroll2.Value / 100
  552. End Sub
  553.  
  554. Private Function capacitor(volts As Double, var As Double)
  555. On Error GoTo err
  556. Dim x As Double
  557.  
  558. x = volts ^ 2 / var
  559. capacitor = 1 / (2 * 3.1416 * 60 * x)
  560. err:
  561. End Function
  562.  
  563. Private Sub VScroll3_Change()
  564. mult = VScroll3.Value * 0.2
  565. Label15 = "ZOOM : " & VScroll3.Value
  566. End Sub
  567.  
  568. Private Sub VScroll3_Scroll()
  569. mult = VScroll3.Value * 0.2
  570. Label15 = "ZOOM : " & VScroll3.Value
  571. End Sub
  572.